<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {

     protected function _initPlugins() {
        $controller = Zend_Controller_Front::getInstance();
        $registry = new Zend_Registry(array(), ArrayObject::ARRAY_AS_PROPS);
        Zend_Registry::setInstance($registry);

        // Add custom routes for detection and mapping
        $router = $controller->getRouter();

        $router->addRoutes(self::_assembleRoutes());
        $controller->setParam('registry', $registry);
        $response = new Zend_Controller_Response_Http;
        $response->setHeader('Content-Type', 'text/html; charset=UTF-8', true);
        $controller->setResponse($response);


        $auth = Zend_Auth::getInstance();
        $acl = new ZendBlog_Auth_AclRole($auth);
        $controller->setParam('auth', $auth);
        $controller->setParam('acl', $acl);
        $controller->registerPlugin(new ZendBlog_Auth_Acl($auth, $acl));
    }

    protected function _initActionHelpers() {
        $this->bootstrap('frontController');
        $navigation = Zend_Controller_Action_HelperBroker::getStaticHelper('Navigation');
        Zend_Controller_Action_HelperBroker::addHelper($navigation);
    }

    protected static function _assembleRoutes() {
        $routes = array();
        $routes['blog1'] = new Zend_Controller_Router_Route_Regex(
                        '([0-9a-zäüöéè\._!;,\+\-%]+)', // all possible single entry URLs
                        array(
                            'module' => 'default',
                            'controller' => 'blog',
                            'action' => 'author'
                        ),
                        array(
                            'user' => 1
                        ),
                        '%s/page/2'
        );
        $routes['blog'] = new Zend_Controller_Router_Route_Regex(
                        '([0-9a-zäüöéè\._!;,\+\-%]+)/page+/(\d+)', // all possible single entry URLs
                        array(
                            'module' => 'default',
                            'controller' => 'blog',
                            'action' => 'author'
                        ),
                        array(
                            'user' => 1,
                            'page' => 2
                        ),
                        '%s/page/%s'
        );
        $routes['entry1'] = new Zend_Controller_Router_Route_Regex(
                        '([0-9a-zäüöéè\._!;,\+\-%]+)/([0-9a-zäüöéè\._!;,\+\-%]+)-(\d+)/page+/(\d+)', // all possible single entry URLs
                        array(
                            'module' => 'default',
                            'controller' => 'blog',
                            'action' => 'entry'
                        ),
                        array(
                            'user' => 1,
                            'blog' => 2,
                            'id' => 3,
                            'page' => 4
                        ),
                        '%s/%s-%s/page/%s'
        );
        $routes['entry'] = new Zend_Controller_Router_Route_Regex(
                        '([0-9a-zäüöéè\._!;,\+\-%]+)/([0-9a-zäüöéè\._!;,\+\-%]+)-(\d+)', // all possible single entry URLs
                        array(
                            'module' => 'default',
                            'controller' => 'blog',
                            'action' => 'entry'
                        ),
                        array(
                            'user' => 1,
                            'blog' => 2,
                            'id' => 3
                        ),
                        '%s/%s-%s/page/2'
        );
        return $routes;
    }

}

